import 'dart:convert' show json;

import 'comment_mode.dart';

T asT<T>(dynamic value) {
  if (value is T) {
    return value;
  }

  return null;
}

class CommentList {
  CommentList({
    this.count,
    this.next,
    this.previous,
    this.results,
  });

  factory CommentList.fromJson(Map<String, dynamic> jsonRes) {
    if (jsonRes == null) {
      return null;
    }

    final List<Comment> results =
    jsonRes['results'] is List ? <Comment>[] : null;
    if (results != null) {
      for (final dynamic item in jsonRes['results']) {
        if (item != null) {
          results.add(Comment.fromJson(asT<Map<String, dynamic>>(item)));
        }
      }
    }
    return CommentList(
      count: asT<int>(jsonRes['count']),
      next: asT<String>(jsonRes['next']),
      previous: asT<String>(jsonRes['previous']),
      results: results,
    );
  }

  int count;
  String next;
  String previous;
  List<Comment> results;

  Map<String, dynamic> toJson() => <String, dynamic>{
    'count': count,
    'next': next,
    'previous': previous,
    'results': results,
  };
  @override
  String toString() {
    return json.encode(this);
  }
}



